package com.xiaoma.tpo.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xiaoma.tpo.dao.ActivityDao;
import com.xiaoma.tpo.domain.Activity;
import com.xiaoma.tpo.dto.ActivityDto;

@Service
public class ActivityService {

	@Autowired
	private ActivityDao activityDao;
	
	public List<ActivityDto> findAll(Integer pageNum, Integer pageSize) {
		return activityDao.findAll(pageNum, pageSize);
	}
	
	public List<Activity> findAll() {
		return activityDao.findAll();
	}
	
	public Integer save(Activity activity) {
		if(activity.getId() == null) {
			return activityDao.insert(activity);
		}else {
			return activityDao.update(activity);
		}
	}
	
	public Activity findById(Integer id) {
		return activityDao.getById(id);
	}
	
	public List<Activity> findByStartDate(Date date) {
		
		Activity activity = new Activity();
		activity.setStartDate(date);
		return activityDao.findByColumns(activity);
	}
	
}
